package com.machine32.classification.tree;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;

/**
 * Identifies what tree the split is for
 * @author murariuf
 *
 */
public class TreeKey implements Writable{

	private int treeKey;
	
	private int splitKey;
	
	@Override
	public void readFields(DataInput stream) throws IOException {
		this.treeKey = WritableUtils.readVInt(stream);
		this.splitKey = WritableUtils.readVInt(stream);
	}

	@Override
	public void write(DataOutput stream) throws IOException {
		WritableUtils.writeVInt(stream, this.treeKey);
		WritableUtils.writeVInt(stream, this.splitKey);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + splitKey;
		result = prime * result + treeKey;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TreeKey other = (TreeKey) obj;
		if (splitKey != other.splitKey)
			return false;
		if (treeKey != other.treeKey)
			return false;
		return true;
	}

}
